package wexin.web.jpa.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import wexin.web.jpa.domain.Article;
import wexin.web.jpa.domain.ArticleType;

@Component("articleService")
@Transactional
public class ArticleServiceImpl implements ArticleService {

	private final ArticleRepository articleRepository;
	
	@Autowired
	public ArticleServiceImpl(ArticleRepository articleRepository) {
		this.articleRepository = articleRepository;
	}
	
	
	@Override
	public Page<Article> findAll(Pageable pageable) {
		Assert.notNull(pageable);
		return articleRepository.findAll(pageable);
	}


	@Override
	public Page<Article> findByType(ArticleType type, Pageable pageable) {
		Assert.notNull(pageable);
		Assert.notNull(type);
		return articleRepository.findByType(type, pageable);
	}

}
